﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Qplus.enums;
using System.Collections.Generic;

namespace Qplus.protocol
{
    public class MessageID : IMessageID
    {
        /**
	    * 协议对应的包
	    */
        private TCPPackage body;
        private static Dictionary<int, MessageID> map;

        private static MessageID instance;

        public TCPPackage getBody()
        {
            if (this.body == null)
            {
                return null;
            }
            return this.body;

        }

        
	    public IMessageID getMessageIDEnum(int id) {
		    return getMessageID(id);
	    }


        /**
	     * 通过消息id获取对应的协议
	     * 
	     * @param id
	     * @return
	     */
        public static MessageID getMessageID(int id)
        {
           return map[id];
        }

        public static MessageID getInstance()
        {
            if (instance == null)
            {
                instance = new MessageID();
            }
            return instance;
        }

        public void setBody(MMessageID a)
        {
            switch (a)
            {
                case MMessageID.C2L_REQ_LOGIN: this.body = new C2L_REQ_LOGIN(); break;
                case MMessageID.L2C_RESP_LOGIN: this.body = new L2C_RESP_LOGIN(); break;
                case MMessageID.C2U_REQ_LOGIN: this.body = new C2U_REQ_LOGIN(); break;
                case MMessageID.C2U_NOTIFY_CLIENT_ONLINE: this.body = new C2U_NOTIFY_CLIENT_ONLINE(); break;
                case MMessageID.C2U_REQ_ENTER_ROOM: this.body = new C2U_REQ_ENTER_ROOM(); break;
                default: this.body = null; break;
            }
        }
       
    }
}
